package com.zyy.smartcity1129.citysubway;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.LineInfo;
import com.zyy.smartcity1129.data.LineMapInfo;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.RvAd;

import java.util.List;

/**
 * @ClassName: LineMapFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 3/12/2021$
 * @Version: 1.0
 */
public class LineMapFragment extends BaseFragment {
    private RecyclerView rvLineMap;
    private ImageView imgLineMap;

    @Override
    protected int layId() {
        return R.layout.f_linemap;
    }

    @Override
    protected String title() {
        return "总览图";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        rvLineMap.setLayoutManager(new LinearLayoutManager(getContext()));
        th(() -> {
            String mapUrl = Http.getInstance().get("/prod-api/api/metro/city", null, LineMapInfo.class, 1).getData().getImgUrl();
            ui(() -> {
                Glide.with(imgLineMap.getContext()).load(Http.base + mapUrl).into(imgLineMap);
            });
        });
        th(() -> {
            List<LineInfo.DataBean> lineList = Http.getInstance().get("/prod-api/api/metro/line/list", null, LineInfo.class, 1).getData();
            RvAd<LineInfo.DataBean> rvAd = new RvAd<LineInfo.DataBean>(lineList, R.layout.rv_text) {
                private void initView(View vi) {
                    tv = (TextView) vi.findViewById(R.id.tv);
                }

                private TextView tv;

                @Override
                protected void initR(View vi, LineInfo.DataBean dataBean, int p) {
                    initView(vi);
                    tv.setText(dataBean.getLineName());
                }
            };
            ui(() -> {
                rvLineMap.setAdapter(rvAd);
            });
        });
    }

    private void initView(View iv) {
        rvLineMap = (RecyclerView) iv.findViewById(R.id.rvLineMap);
        imgLineMap = (ImageView) iv.findViewById(R.id.imgLineMap);
    }
}
